package com.czl.module_service.adapter.asset

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.UsageBean
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemMyUsageApplyBinding
import com.czl.module_service.fragment.assetUse.MyUsageApplyFragment

class MyUsageApplyAdapter(private val fragment: MyUsageApplyFragment) :
    BaseQuickAdapter<UsageBean, BaseDataBindingHolder<ItemMyUsageApplyBinding>>(
        R.layout.item_my_usage_apply
    ) {

    private var applicationUseId : Int? = 0
    private var applicationType : Int? = 0
    private var taskUserId : String = ""
    var tabIndex : Int = 1

    override fun convert(
        holder: BaseDataBindingHolder<ItemMyUsageApplyBinding>,
        item: UsageBean,
    ) {
        if (item.applicationType == 0) {
            item.applicationTitle = item.userName + "提交的领用申请"
            item.note = "领用原因：" + item.note
        } else {
            item.applicationTitle = item.userName + "提交的借用申请"
            item.note = "借用原因：" + item.note
        }
        holder.dataBinding?.run {
            data = item
            adapter = this@MyUsageApplyAdapter
            executePendingBindings()
        }
    }

    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is UsageBean) {
            applicationUseId = it.applicationUseId
            applicationType = it.applicationType
            taskUserId = if (tabIndex == 2 && it.processStatus == 1 && it.ttStatus == 2 && it.taskUserId != null) {
                it.taskUserId.toString()
            } else {
                ""
            }
            val bundle = Bundle()
            bundle.putString("applicationUseId", it.applicationUseId.toString())
            bundle.putString("applicationType", applicationType.toString())
            bundle.putString("tabIndex", tabIndex.toString())
            bundle.putString("taskUserId", taskUserId)
            fragment.startContainerActivity(AppConstants.Router.Service.F_SERVICE_MY_USAGE_APPLY_DETAIL, bundle)
        }
    })
}
